package com.promote.algorithm;

import java.util.Arrays;

/**
 * @ClassName NumRescueBoats
 * Description 881 救生艇
 * @Author LiZiHao
 * Date 2023/4/8 15:31
 * @Version 1.0
 **/
public class NumRescueBoats {
    //双指针算法解决
    public int numRescueBoats(int[] people, int limit) {
        Arrays.sort(people);
        int res = 0;
        int i = 0,j = people.length-1;
        while (i<=j) {
            if (people[i]+people[j]<=limit) {
                res++;
                i++;
                j--;
            } else {
                res++;
                j--;
            }
        }
        return res;
    }
}
